

%initialisation:
n=1;
p=(sqrt(n^2+4)-n)/2;                          %condition: p<1/n
vn=p*p;
lag=2
[w,pBomber]=prepareBomber(vn,n);



    
%number of Wins for ship and Bomber
shipW=0
bomberW=0

for games=1:1
    
    
    %Initialisation
    switchAB=0; %nr of switchs between A and B
    t=0;        %Time; Time in the whole context
    tdrop=0;    % 'local' time to drop the bomb; at which switch between A and B the bomb should be dropped
    explosionTime=-1;  %Time in the whole context, when the bomb explodes  


    v_Ship=zeros(1,0);   %Vector of the ship; empty at the beginning
    v_Bomber=zeros(1,0); %Vector of the bomber; empty at the beginning

    last=0;              % last position
    last2=last;          % position before last


    while(true)
    
        if(t==explosionTime)
            if(compareVectors(v_Ship,v_Bomber)==1)
                text='bomber wins'  ;
                bomberW=bomberW+1;
            else
                text='ship wins';
                shipW=shipW+1;
            end
            break
        end
 
        
        if(explosionTime==-1)
            [v_Bomber,explosionTime, tdrop]=dropBomb(v_Ship, switchAB, tdrop ,n,last,t,lag, pBomber);
        end
        
        last2=last;
    
        [v_Ship, last]= moveShip(v_Ship, last, t,p,n);
    
    
     %count #switches between A and B
        if(t==0)
           switchAB=1 ;
        else
            switchAB=(last==last2)*(switchAB+1);
        end
    
    

    t=t+1;
    
    end
end



shipW
bomberW
games
shipWins=shipW/games
bomberWins=bomberW/games

